package com.example.tianhao.httpclient;

import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import java.net.HttpURLConnection;

import static android.webkit.ConsoleMessage.MessageLevel.ERROR;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{
    protected static final int SUCCESS=1;
    protected static final int ERROR=2;
    private HttpURLConnection httpURLConnection;

    private EditText e;
    private Button btnfind;
    private TextView tv;

    private Handler handler = new Handler()
    {
        public void handleMessage(Message msg)
        {
            switch (msg.what)
            {
                case SUCCESS:
                    String text=(String) msg.obj;
                    tv.setText(text);
                    break;
                case ERROR:
                    Toast.makeText(MainActivity.this, "请求失败", Toast.LENGTH_SHORT).show();
                    break;

            }
        }

    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();
    }
    private void init(){
        e = (EditText)findViewById(R.id.editText);
        btnfind = (Button)findViewById(R.id.button);
        tv = (TextView)findViewById(R.id.textView);
        btnfind.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        System.out.println("按钮被按下！");
    }
}
